<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo</title>
  <script type="text/javascript" src="../vue.js"></script>
</head>

<body>
  <!-- 原理是拿原数据做参考来生成属性 遍历属性渲染页面 computed计算属性监听的属性一旦发生变化 他也会重新执行并重新渲染 -->
  <div id="app">
    <h1>人员列表</h1>
    <input type="text" v-model="keyWord">

    <ul>
      <li v-for="item of person2">{{item.name}}-{{item.age}}-{{item.gender}}</li>
    </ul>
  </div>
</body>
<script type="text/javascript">
  Vue.config.productionTip = false
  const vm = new Vue({
    el: "#app",
    data() {
      return {
        person: [
          { id: '001', name: '马冬梅', age: 19, gender: '女' },
          { id: '004', name: '帅邓伦', age: 22, gender: '男' },
          { id: '002', name: '周冬雨', age: 20, gender: '女' },
          { id: '003', name: '周杰伦', age: 21, gender: '男' },
        ],
        keyWord: ''
      }
    },
    computed: {
      person2() {
        // 将排序后的值根据查询的关键字显示出来 这里监听的是person2和keyWord 一旦发生变化就会重新渲染
        return this.person.filter(item => item.name.includes(this.keyWord)).sort((a, b) => a.age - b.age)

      }
    }
  })
</script>

</html>